package cn.fengliu.controller.adm;

import cn.fengliu.Dao.ClzDao;
import cn.fengliu.Dao.CourseDao;
import cn.fengliu.Dao.TaskDao;
import cn.fengliu.Dao.UserDao;
import cn.fengliu.entity.Clz;
import cn.fengliu.entity.Course;
import cn.fengliu.entity.Task;
import cn.fengliu.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;

@Controller   //创建对象，并且装配到 IOC容器
@RequestMapping("/task")
public class TaskController {
   @Autowired
   TaskDao taskDao;
   @Autowired
   ClzDao clzDao;
   @Autowired
   CourseDao courseDao;
   @Autowired
   UserDao userDao;


   @RequestMapping("/show")
    public String findAll(Model model){
       List<TaskDao> tasks = taskDao.findAll();

       List<User> teas = userDao.findUser("tea");

       List<Clz> clzs = clzDao.findAll();
       List<Course> cours = courseDao.findAll();
       System.out.println(clzs);
       System.out.println(cours);

       model.addAttribute("teas",teas);

       model.addAttribute("clzs",clzs);
       model.addAttribute("cours",cours);

       model.addAttribute("tasks",tasks);
       return"/adm/task/show";
   }
   @RequestMapping("/go2add")
    public String go2add(Model model){
       return "forward:/task/show";
        }
        @RequestMapping("add")
    public String add(User user, Clz clz, Course course){

            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("uid",user.getUid());
            map.put("clzno", clz.getClzno());
            map.put("cno",course.getCno());
            System.out.println(map);
            taskDao.add(map);
       return "forward:/task/show";
        }
        @RequestMapping("del/{kid}")
    public String del(@PathVariable("kid") Integer id){
       taskDao.del(id);
       return "forward:/task/show";
        }

}
